<template>
  <div class="app-container" >
    <el-row>
      <el-col :span="5" style="margin-left: -20px;">
                <div class="head-container">
                  <el-scrollbar style="height: 480px">
                    <el-tree :data="deptOptions" :props="defaultProps" :expand-on-click-node="false"
                      :filter-node-method="filterNode" ref="tree" node-key="id" default-expand-all highlight-current
                      @node-click="handleNodeClick" />
                  </el-scrollbar>
                </div>
      </el-col>
      <el-col :span="19">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px" >
          <el-form-item label="产品类别" prop="productType">
            <el-select v-model="queryParams.productType" placeholder="请选择产品类别" >
              <el-option
                v-for="dict in dict.type.product_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="产品编号" prop="productNo">
            <el-input
              v-model="queryParams.productNo"
              placeholder="请输入产品编号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="产品名称" prop="productName">
            <el-input
              v-model="queryParams.productName"
              placeholder="请输入产品名称"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="产品状态" prop="productStatus">
            <el-select v-model="queryParams.productStatus" placeholder="请选择产品状态" clearable>
              <el-option
                v-for="dict in dict.type.product_status"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
        </el-row>

        <el-table :row-style="{ height: '30px' }"  :cell-style="{ padding: '0px' }" height="450" border v-loading="loading" :data="qualificationList" @selection-change="handleSelectionChange" highlight-current-row>
          <el-table-column
            label="序号"
            type="index"
            :index="indexMethod"/>
          <el-table-column label="机构名称" align="center" prop="organizationName" width="100px" :show-overflow-tooltip="true" />
          <el-table-column label="发布时间" align="center" prop="releaseTime" width="100px" v-if="columns[0].visible">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.releaseTime, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="产品类别" align="center" prop="productType" :show-overflow-tooltip="true" v-if="columns[1].visible">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.product_type" :value="scope.row.productType"/>
            </template>
          </el-table-column>
          <el-table-column label="产品编号" align="center" prop="productNo" width="100px" :show-overflow-tooltip="true" v-if="columns[2].visible"/>
          <el-table-column label="产品名称" align="left" prop="productName" :show-overflow-tooltip="true" v-if="columns[3].visible"/>
          <el-table-column label="定价范围" align="center" prop="productPrice" :show-overflow-tooltip="true" v-if="columns[4].visible"/>
          <el-table-column label="发证机构" align="center" prop="certificateInstitution" :show-overflow-tooltip="true" v-if="columns[5].visible"/>
          <el-table-column label="查询网址" align="center" prop="selectUrl" :show-overflow-tooltip="true" v-if="columns[6].visible">
            <template slot-scope="scope">
              <!-- 使用按钮作为可点击元素，并绑定点击事件 -->
              <el-button @click="handleClick(scope.row.selectUrl)" type="text">
                {{ scope.row.selectUrl }}
              </el-button>
            </template>
          </el-table-column>
          <el-table-column label="产品介绍" align="center" prop="productRemark" :show-overflow-tooltip="true" v-if="columns[7].visible">
            <template slot-scope="scope">
              <div class="ellipsis-cell" :title="scope.row.productRemark">{{ scope.row.productRemark }}</div>
            </template>
          </el-table-column>
          <el-table-column label="产品状态" align="center" prop="productStatus" :show-overflow-tooltip="true" v-if="columns[8].visible">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.product_status" :value="scope.row.productStatus" :class="{'red-text': scope.row.approve === 0}"/>
            </template>
          </el-table-column>
          <el-table-column label="创建人" align="center" prop="userName" :show-overflow-tooltip="true" width="100" v-if="columns[9].visible"/>
          <el-table-column label="创建时间" align="center" prop="creationTime" width="100px" :show-overflow-tooltip="true" v-if="columns[10].visible"/>
          <el-table-column label="执行文件" align="center" prop="exeStandard" >
            <template slot-scope="scope">
              <el-button  v-if="scope.row.exeStandardUrl!==null" @click.stop="handlePictureCardPreview(scope.row.exeStandard,exeStandardCode)" size="small"
                         type="text">附件</el-button>
              <el-button size="small" v-else type="text">无附件</el-button>
            </template>
          </el-table-column>
          <el-table-column label="样板" align="center" prop="template" >
            <template slot-scope="scope">
              <el-button v-if="scope.row.templateUrl!==null" @click.stop="handlePictureCardPreview(scope.row.template,businessCode)" size="small"
                         type="text">附件</el-button>
              <el-button size="small" v-else type="text">无附件</el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />

      </el-col>
    </el-row>
    <!--   履历 附件展示对话框-->
    <el-dialog title="查看附件" :visible.sync="openFileList" width="500px" append-to-body v-if="openFileList">
      <UploadFile :upload-id="uploadId" :business-code="UploadCode"></UploadFile>
    </el-dialog>
  </div>
</template>

<script>
import { listQualificationAll, orgQualification, delQualification, addQualification, updateQualification,approveStatus } from "@/api/qualificationInfo/qualification";
import FileView from "@/components/FileView/index"
import { getToken } from "@/utils/auth";
import SelectUser from "../system/role/selectUser.vue";
import MainType from "@/components/MainType/index"
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import {listType} from "@/api/maintype/type";
import UploadFile from "../upload/index.vue";
export default {
  name: "Qualification",
  dicts: ['product_type', 'product_status','customer_industry', 'administrative_area','qualification_resume_status'],
  components: {UploadFile, FileView,SelectUser,MainType,Treeselect },
  data() {
    return {
      //主类别
      typeCode:'qualification',
      // 遮罩层
      loading: true,
      loadingEnter:true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      //修改页面中的序号展示
      index:0,
      addSign:0,
      // 显示搜索条件
      showSearch: true,
      //附件标志位
      isUpload:false,
      // 总条数
      total: 0,
      //判断是否用自定义的下拉框还是数据字典的下拉框
      addStatus:1,
      // 证书类型选项
      deptOptions: undefined,
      defaultProps: {
        children: "children",
        label: "label"
      },
      // 资质产品管理表格数据
      qualificationList: [],
      // 企业信息表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //弹出框选择，默认为0
      typeSelect:0,
      businessCode:'qualification',
      exeStandardCode:'exeStandard',
      //统计查看样板和执行标准的附件
      UploadCode:'',
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 15,
        productType: null,
        productNo: null,
        productName: null,
        productStatus: null,
        classificationId:null,
        organizationId:null
      },
      //产品状态
      op:[{
        value: 1,
        label: '上架'
      }],
      dialogImageUrl: '',
      ImgDig:false,
      //主分类
      options:null,
      //履历对话框标志
      resumeOpen:false,
      //附件对话框
      openFileList:false,
      resumeFileList:false,
      uploadId:null,
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/qualificationInfo/qualification/importData"
      },
      //第二层的查询条件
      queryParamsTwo: {
        pageNum: 1,
        pageSize: 15,
        enterpriseName: null,
        administrativeArea: null,
        enterpriseLabel: null,
        industry: null,
      },
      //外协id
      enterId:[],
      //外协名称集合
      enterName:[],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        productType: [
          { required: true, message: '请选择产品类别', trigger: 'change' }
        ],
        productNo: [
          { required: true, message: '请输入产品编号', trigger: 'blur' }
        ],
        productName: [
          { required: true, message: '请输入产品名称', trigger: 'blur' }
        ],
        certificateInstitution: [
          { required: true, message: '请输入发证机构', trigger: 'blur' }
        ],
        productStatus: [
          { required: true, message: '请选择产品状态', trigger: 'change' }
        ],
        productRemark: [
          { required: true, message: '请输入产品介绍', trigger: 'blur' }
        ],
        releaseTime: [
          { required: true, message: '请选择发布时间', trigger: 'change' }
        ]
        // 如果有其他字段需要添加校验规则，请继续在此处添加
      },
      resumeRules:{
        operateTime: [
          { required: true, message: '请选择更新时间', trigger: 'change' }
        ],
        operateName: [
          { required: true, message: '请选择更新人', trigger: 'change' }
        ],
        approveName: [
          { required: true, message: '请选择审批人', trigger: 'change' }
        ],
        operateContent: [
          { required: true, message: '请输入更新内容', trigger: 'blur' }
        ]
      },
      // 列信息
      columns: [
        { key: 0, label: `发布时间`, visible: true },
        { key: 1, label: `产品类别`, visible: true },
        { key: 2, label: `产品编号`, visible: true },
        { key: 3, label: `产品名称`, visible: true },
        { key: 4, label: `定价范围`, visible: true },
        { key: 5, label: `发证机构`, visible: true },
        { key: 6, label: `查询网址`, visible: true },
        { key: 7, label: `产品介绍`, visible: true },
        { key: 8, label: `产品状态`, visible: true },
        { key: 9, label: `创建人`, visible: true },
        { key: 10, label: `创建时间`, visible: true },
      ],
      //履历对话框标题
      resumeTitle:null,
      //履历新增或删除标志
      openResumeWX:false,
      formResume:{},
      userType:"1",
      Resign:'1',
      show:null,
      //控制履历附件
      showResume:false
    };
  },
  created() {
    this.getDeptTree();
    this.getList();
    this.listType();
  },
  methods: {
    //获取树节点数据
    listType(){
      listType({typeCode:'qualification'}).then(res=>{
        this.options=res.data;
      })
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    // 节点单击事件
    handleNodeClick(data) {
      this.queryParams.organizationId = data.id;
      this.handleQuery();
    },
    getDeptTree() {
      orgQualification().then(response => {
        this.deptOptions = response.data;
      });
    },
    /** 查询资质产品管理列表 */
    getList() {
      this.loading = true;
      listQualificationAll(this.queryParams).then(response => {
        console.log(response.rows)
        this.qualificationList = response.rows;
        this.total = response.total;
        console.log(this.total)
        this.loading = false;
      });
    },
    //点击查询网址
    handleClick(url){
      if (!url.startsWith('http://') && !url.startsWith('https://')) {
        // 如果没有协议，添加默认的http://协议
        url = 'http://' + url;
      }      window.open(url, '_blank');
    },
    //序号展示
    indexMethod(index){
      return index+1;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.classificationId=null
      this.queryParams.productStatus=null
      this.queryParams.productName=null
      this.queryParams.productType=null
      this.queryParams.productNo=null
      this.queryParams.organizationId=null
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    // 多选框选中数据
    handleSelectionChangeEnter(selection) {
      this.enterId = selection.map(item => item.enterpriseId)
      this.enterName = selection.map(item => item.enterpriseName)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 搜索按钮操作 */
    handleQueryEnter() {
      this.queryParams.pageNum = 1;
      this.getListEnter();
    },
    //企业重置
    resetQueryEnter(){
      this.resetForm("queryFormEnter");
      this.handleQueryEnter();
    },
    handlePictureCardPreview(id,code) {
      this.uploadId=id;
      this.UploadCode=code;
      this.openFileList = true;
    },
  }
};
</script>
<style>
#inp{
  width: 202.5px;
}
.ellipsis-cell {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.red-text {
  color: red;
}
</style>
